<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <title>亿人宝 - 余额提现</title>
    <meta content="" name="keywords"/>
    <meta content="" name="description"/>
    <link rel="stylesheet" th:href="@{/css/common.css}"/>
    <link rel="stylesheet" th:href="@{/css/user.css}" type="text/css"/>
    <link rel="stylesheet" th:href="@{/css/jquery.datetimepicker.css}" type="text/css"/>
    <script th:src="@{/script/jquery.min.js}" type="text/javascript"></script>
    <script th:src="@{/script/common.js}" type="text/javascript"></script>
    <script th:src="@{/script/user.js}" type="text/javascript"></script>
    <script th:src="@{/layui/layer/layer.js}" type="text/javascript"></script>
</head>
<body>
<div th:replace="common/public::head"></div>
<!--个人中心-->
<div class="wrapper wbgcolor">
    <div class="w1200 personal">
        <!--<div class="credit-ad"><img height="96" th:src="@{/images/clist1.jpg}" width="1200"></div>-->
        <div class="personal-left" id="personal-left">
            <ul>
                <li><span><a th:href="@{/per/index(option = 1)}"><i class="dot dot1"></i>账户总览</a></span></li>
                <li><span><a style="font-size:14px;text-align:center;width:115px;padding-right:35px;" th:href="@{/cap/cap_List}">资金记录</a></span></li>
                <li><span><a style="font-size:14px;text-align:center;width:115px;padding-right:35px;" th:href="@{/per/investlist(option = 1)}">投资记录</a></span>
                </li>
                <li><span><a style="font-size:14px;text-align:center;width:115px;padding-right:35px;" th:href="@{/per/prolist}">回款计划</a></span></li>
                <li><span><a th:href="@{/per/thirdparty}"><i class="dot dot02"></i>开通第三方</a> </span></li>
                <li><span><a th:href="@{/per/torecharge}"><i class="dot dot03"></i>充值</a></span></li>
                <li class="pleft-cur"><span><a th:href="@{/per/towithdrawal}"><i class="dot dot04"></i>提现</a></span></li>
                <li style="position:relative;"><span> <a th:href="@{/per/toredenvelopes(state = 1)}"> <i class="dot dot06"></i> 我的红包 </a> </span></li>
                <li style="position:relative;"><span> <a th:href="@{/per/tomessages}"><i class="dot dot08"></i>系统信息 </a> </span></li>
                <li><span><a th:href="@{/setUser/toView}"><i class="dot dot09"></i>账户设置</a></span></li>
            </ul>
        </div>
        <label id="typeValue" style="display:none;"> </label>
        <script>
            //防触蒙版
            function showSpan(op) {
                var thi = $("#thi").val().trim();
                if (thi == 0) {
                    $("body").append("<div id='mask'></div>");
                    $("#mask").addClass("mask").css("display", "block");

                    $("#" + op).css("display", "block");
                }
            }

        </script>
        <div class="personal-main">
            <div class="personal-deposit">
                <h3><i>提现</i></h3>
                <form action="#" id="form" method="post" name="form" onsubmit="return withdrawal()" target="_blank">
                    <div class="deposit-form" style="margin-top:0px;border-top:0px none;">
                        <h6>填写提现金额</h6>
                        <ul>
                            <li>
                                <span class="deposit-formleft">可用金额</span>
                                <span class="deposit-formright">
                                    <i>
                                        <label class="balance" id="form:blance" th:text="${user.balance}"> 0.00</label>
                                    </i>
                                    元
                                </span>
                            </li>
                            <li>
                                <span class="deposit-formleft">提现金额</span>
                                <span class="deposit-formright">
                                    <input class="deposite-txt" id="withdrawalamount" maxlength="7" name="withdrawalamount"
                                           onkeyup="value=value.replace(/[^\d\.]/g,'')" placeholder="请输入您要提现的金额" type="text">
                                    元
                                </span>
                                <span id="actualMoneyErrorDiv">
                                    <span class="error" id="actualMoney_message" style="display:none"></span>
                                </span>
                            </li>
                            <li>
                                <span class="deposit-formleft">提现费用</span>
                                <em class="markicon fl" id="txfy"></em>
                                <span class="deposit-formright deposit-formright1">
                                    <i>
                                        <label class="cost" id="form:fee"> 0.00</label>
                                    </i>
                                    元
                                </span>
                                <span class="txarrow-show">提现金额的0.1%，最低不低于2元，最高100元封顶</span>
                                <span class="txicon-show"></span>
                            </li>
                            <li>
                                <span class="deposit-formleft">实际到账金额</span>
                                <em class="markicon fl" id="dzje"></em>
                                <span class="deposit-formright deposit-formright1">
                                    <i>
                                        <label class="amountreceived" id="form:cashFine"> 0.00</label>
                                    </i>
                                    元
                                </span>
                                <span class="dzarrow-show">提现金额 - 提现费用</span>
                                <span class="dzicon-show"></span>
                            </li>
                            <li>
                                <input class="btn-depositok" name="form:j_idt78" type="submit" value="提现">
                            </li>
                        </ul>
                    </div>
                </form>
                <div class="deposit-tip"> 温馨提示：<br>
                    1、用户需在完成身份认证、开通丰付托管账户并绑定银行卡后，方可申请提现；<br>
                    2、请务必在提现时使用持卡人与身份认证一致的银行卡号，且确保填写信息准确无误；<br>
                    3、工作日当天16:00前提交的提现申请将在当天处理，默认为T+1到账；<br>
                    4、提现金额单笔上限为50万元，单日累计总额不可超过100万元；<br>
                    5、提现手续费为提现金额的0.1%，最低每笔2元，100元封顶，手续费由第三方托管账户收取，用户自行承担。<br>
                </div>
            </div>
        </div>
        <input id="thi" th:value="${thi}" type="hidden"/>
        <div class="alert-450 alert-h220" id="alert-notOpenAccount" style="display: block;" th:if="${thi == 0}">
            <div class="alert-title">
                <h3>提示</h3>
            </div>
            <div class="alert-main">
                <form id="notOpenAccountForm">
                    <p align="center" class="msg6"> 用户在充值或提现前，需开通第三方账户。<br>
                        此页面将在5秒后自动跳转到开通第三方账户页面<br>
                        <em id="show-number">5</em></p>
                    <a class="btn-ok txt-center" id="openAccountAId" th:href="@{/per/thirdparty}">马上开通第三方账户</a>
                </form>
            </div>
        </div>
        <script type="text/javascript">
            $("#form\\:actualMoney").focus(
                function () {
                    $(this).css({"font-size": "24px", "font-weight": "bold", "font-family": "Arial", "border": "1px solid #0caffe"});
                    if ($("#form\\:actualMoney").val() == value) {
                        $("#form\\:actualMoney").val("");
                        $(this).css({"font-size": "24px", "font-weight": "bold", "font-family": "Arial"});
                    }
                }).blur(
                function () {
                    $(this).css("border", "1px solid #D0D0D0");
                    if ($("#form\\:actualMoney").val() == "") {
                        $(this).css({"color": "#D0D0D0", "font-size": "14px", "font-weight": "normal"});
                    }
                });
        </script>
        <script type="text/javascript">
            var url = "[[@{/per/thirdparty}]]";
            $("#openAccountAId").attr("href", url);
            showSpan('alert-notOpenAccount');
            countDown('show-number', 5, url);
        </script>
        <div class="clear"></div>
    </div>
</div>
<!--网站底部-->
<div class="ft" id="footer">
    <div th:replace="common/public::footer"></div>
</div>
<script type="text/javascript">
    var a = false;
    var balances = $(".balance").text();  //账户余额
    $(".balance").text((parseFloat(balances)).toFixed(2));
    $("#withdrawalamount").blur(window.oninput = function () {  //window.oninput = :此事件会在value属性值发生改变时触发，通过js改变value属性值不会触发此事件。
        var balance = $(".balance").text();  //账户余额
        var withdrawalamount = (parseFloat($("#withdrawalamount").val().trim())).toFixed(2);  //提现金额
        var actualMessage = $("#actualMoney_message");  //提示行
        console.log(withdrawalamount);
        //提现金额最多小数位
        var legalRegex = "^(([1-9]+[0-9]*)|((([1-9]+[0-9]*)|0)\\.[0-9]{1,2}))$";
        var legalPattern = new RegExp(legalRegex);
        var daxiao = balance - withdrawalamount;  //比较大小(double类型不能直接比较大小（至少在此处是这样），所以需要转换一下！)
        if (withdrawalamount == "" | withdrawalamount == null | withdrawalamount == 'NaN') {
            $(".cost").text((parseFloat(0)).toFixed(2));
            $(".amountreceived").text((parseFloat(0)).toFixed(2));
            $(actualMessage).text("请输入您要提现的金额");
            $(actualMessage).show();
            a = false;
        } else if (daxiao < 0) {
            $(".cost").text((parseFloat(0)).toFixed(2));
            $(".amountreceived").text((parseFloat(0)).toFixed(2));
            $(actualMessage).text("您的账户余额不足");
            $(actualMessage).show();  //show():显示隐藏元素。hide():隐藏元素。
            a = false;
        } else if (!legalPattern.test(withdrawalamount)) {
            $(".cost").text((parseFloat(0)).toFixed(2));
            $(".amountreceived").text((parseFloat(0)).toFixed(2));
            $(actualMessage).text("小数位最多两位!");
            $(actualMessage).show();
            a = false;
        } else if (withdrawalamount < 2 | withdrawalamount > 500000) {
            $(".cost").text((parseFloat(0)).toFixed(2));
            $(".amountreceived").text((parseFloat(0)).toFixed(2));
            $(actualMessage).text("提现金额必须大于2.00 元，单笔不超过50 万");
            $(actualMessage).show();
            a = false;
        } else {
            var cost = withdrawalamount * 0.001;  //手续费
            var amountreceived = withdrawalamount;  //实际到账金额
            if (cost < 2) {
                $(actualMessage).text("");
                $(actualMessage).hide();
                $(".cost").text((parseFloat(2)).toFixed(2));
                $(".amountreceived").text((parseFloat(amountreceived - 2)).toFixed(2));
                a = true;
            } else if (cost > 100) {
                $(actualMessage).text("");
                $(actualMessage).hide();
                $(".cost").text((parseFloat(100)).toFixed(2));
                $(".amountreceived").text((parseFloat(amountreceived - 100)).toFixed(2));
                a = true;
            } else {
                $(actualMessage).text("");
                $(actualMessage).hide();
                $(".cost").text((parseFloat(cost)).toFixed(2));
                $(".amountreceived").text((parseFloat(amountreceived - cost)).toFixed(2));
                a = true;
            }
        }
    });

    function withdrawal() {
        var withdrawalamount = $("#withdrawalamount").val().trim();
        if (a) {
            layer.prompt({title: '请输入支付密码', formType: 1}, function (pass, index) {
                let zzz = layer.load();
                $.ajax({
                    url: '/erb/per/withdrawal',
                    type: 'post',
                    async: false,
                    data: {pwd: pass, amount: withdrawalamount},
                    dataType: 'json',
                    success: function (data) {
                        layer.close(zzz);
                        if (data == 0) {
                            layer.msg('支付密码错误！', {
                                icon: 2
                            });
                        } else if (data == 1) {
                            layer.close(index);
                            layer.msg('提现成功！', {time: 1000, icon: 1}, function () {
                                location.reload()
                            });
                        }
                    }
                })
            });
        }
        return false;
    }
</script>
</body>
</html>
